// #define print(...)

#define abs(i) ((i)<0 ? -(i) : (i))
class Solution {
public:
int threeSumClosest(vector<int>& nums, int target) {
    sort(nums.begin(), nums.end());
    print(nums, "\n")
    int ans = nums[0] + nums[1] + nums[2];
    for(auto s=nums.begin(); s !=nums.end()-2; s++){
        auto m=s+1, b = nums.end()-1;
        while(m<b){
            print(*s, ' ', *m, ' ', *b, "\n")
            auto sum = *s + *m + *b;
            if(sum == target) return sum;
            if(abs(sum-target) < abs(ans-target))
                ans = sum;
            sum < target ? m++ : --b;
        }
    }
    return ans;
}
};
